﻿Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports BBDD
Imports Controladores

 _

Class comprarAcValorPref
   Inherits System.Web.UI.Page

   Protected Sub Page_Load(sender As Object, e As EventArgs)
      If Session("privUser") Is Nothing Or Integer.Parse(Session("privUser").ToString()) < 1 Then
         Response.Redirect("index.aspx")
      Else
         If Integer.Parse(Session("privUser").ToString()) = 1 Then
            campoDNI.Text = Session("DNIUser").ToString()
            campoDNI.Enabled = False
         
         
         Else
            campoDNI.Enabled = True
         End If 
      End If
      
      listaAcciones.Value = Consultas.listarAcciones()
   End Sub 'Page_Load
   
   
   Protected Sub boton_comprarValor_Click(sender As Object, e As EventArgs)
      
      If campoDNI.Text = "" Or Not Consultas.existeUsuario(campoDNI.Text.ToString()) Then
         controlador.CreateMessageAlert(Me, "No existe tal usuario", "msg")
      Else
         If campoCantidad.Text = "" Then
            campoCantidad.Text = "-1"
         End If
         
         
            Session("error") = controlador.comprarAccion(campoDNI.Text.ToString(), campoSimbolo.Text.ToString(), Integer.Parse(campoCantidad.Text.ToString()))
         If Session("error").ToString() = "" Then
            controlador.CreateMessageAlert(Me, "Operacion llevada con éxito", "msg")
            Me.campoCantidad.Text = ""
            Me.campoSimbolo0.Text = ""
         Else
            controlador.CreateMessageAlert(Me, Session("error").ToString(), "msg")
         End If
      End If
   End Sub 'boton_comprarValor_Click 
End Class 'comprarAcValorPref